package web.dao.Impl;

import web.bean.Chewei;
import web.bean.Dongshu;
import web.dao.CheWeiDao;
import web.dao.DongshuDao;
import web.utils.DBUtil;

import java.util.List;

public class DongShuDaoImpl implements DongshuDao {
    @Override
    public List<Dongshu> findInfo(Integer params1, Integer params2, String startTime, String endTime, String name) {
        return DBUtil.findByWhere(Dongshu.class,"addtime>=? and addtime<=? and suoshuxiaoqu like ?  limit ?,?",startTime,endTime,"%"+name+"%",params1,params2);
    }

    @Override
    public int count(String startTime, String endTime, String name) {
        return DBUtil.findByWhere(Chewei.class,"addtime>=? and addtime<=? and suoshuxiaoqu like ? ",startTime,endTime,"%"+name+"%").size();
    }

    @Override
    public int add(Dongshu dongshu) {
        return DBUtil.insert(dongshu);
    }

    @Override
    public int del(Integer[] deleteId) {
        String where="id in (";
        for (int i = 0; i < deleteId.length; i++) {
            where=where+"?";
            if (i!=deleteId.length-1){
                where=where+",";
            }else {
                where=where+")";
            }
        }
        return DBUtil.delete(Dongshu.class,where,deleteId);
    }

    @Override
    public Dongshu findNameById(Integer id) {
        return DBUtil.findOneByWhere(Dongshu.class,"id=?",id);
    }

    @Override
    public List<Dongshu> findNameAll() {
        return DBUtil.findAll(Dongshu.class);
    }

    @Override
    public List<Dongshu> findDongShuAll(Integer id) {
        return DBUtil.findByWhere(Dongshu.class,"xiaoquId=?",id);
    }

    @Override
    public int editInfo(Dongshu dongshu) {
        return DBUtil.updateSelective(dongshu,"id=?",dongshu.getId());
    }
}
